<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>投骰子猜大小</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="{:RES}/jinrong/Mobile/Public/js/dice/css/jquery.select.css">
    <link rel="stylesheet" href="{:RES}/jinrong/Mobile/Public/css/common.css">
    <link rel="stylesheet" href="{:RES}/jinrong/Mobile/Public/css/ucenter.css">
    <link rel="stylesheet" href="{:RES}/jinrong/Mobile/Public/css/option_common.css">
    <link rel="stylesheet" href="{:RES}/jinrong/Mobile/Public/css/option_index.css">
    <style type="text/css">
        html, body, canvas, div {
            padding: 0;
            margin: 0;
        }

        canvas {
            width: 100%;
        }

        body,html {
            background-color: #000;
            display: inherit;
            -webkit-box-orient: inherit;
            -webkit-box-align: inherit;
        }
        .skull_select{display:none;}
        .skull_list li.checked{background: #f1bc11;}
        .loading-wrapper .loading-area{font-size: 20px;font-weight: bold;background: #e7ff9f;top:40%;}
        .loading-wrapper .loading-area h3{color:red; font-size: 20px;margin:5px 0;}
        .loading-wrapper .loading-area p{font-size: 14px;color:#6d1e1e;}
        .pwd-btn {
            display: block;
            width: 80%;
            margin: 5px auto 0;
            border: 0;
            border-radius: 5px;
            background: #daac33;
            padding: .5rem 0;
            cursor: pointer;
            font-size: 1.5rem;
            text-align: center;
            color: #fff;
        }
        .active ul li{width:18%;}

    </style>

    <script src="{:RES}/jinrong/Mobile/Public/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="{:RES}/jinrong/Mobile/Public/js/dice/js/lufylegend-1.9.1.simple.min.js"></script>
    <script type="text/javascript" src="{:RES}/jinrong/Mobile/Public/js/dice/js/lufylegend.ui-0.14.1.min.js"></script>
    <script type="text/javascript" src="{:RES}/jinrong/Mobile/Public/js/dice/js/zepto.min.js"></script>
    <script type="text/javascript" src="{:RES}/jinrong/Mobile/Public/js/dice/js/jquery.select.js"></script>
    <script type="text/javascript" src="{:RES}/jinrong/Mobile/Public/js/common.js"></script>
</head>
<body>
<!--<script src="{:RES}/jinrong/Mobile/Public/js/dice/5miaojs.js"></script>-->
<div id="mylegend">loading……</div>
<div class="loading-wrapper" style="display: none;">
    <div class="loading-area">
        <div id="floatingBarsG1" class="floatingBarsG"></div>
        <div id="msg"></div>
    </div>
</div>
<!--<select id="selBottom" style="display:none;">-->
    <!--<option value="10">10元</option>-->
    <!--<option value="9">9元</option>-->
    <!--<option value="8">8元</option>-->
    <!--<option value="7">7元</option>-->
    <!--<option value="6">6元</option>-->
    <!--<option value="5">5元</option>-->
    <!--<option value="4">4元</option>-->
    <!--<option value="3">3元</option>-->
    <!--<option value="2">2元</option>-->
    <!--<option value="1">1元</option>-->
<!--</select>-->
<div class="pop-box none" id="buildBox">
    <nav class="pop-nav">
        <a href="javascript:void(0);" class="back"></a>
        <h3>选择投注金额</h3>
    </nav>
    <div class="active">
        <h1>投注：<b>10</b>元</h1>
        <ul>
            <li class="slct">
                <p><i>10</i>元</p>
            </li>
            <li>
                <p><i>9</i>元</p>
            </li>
            <li>
                <p><i>8</i>元</p>
            </li>
            <li>
                <p><i>7</i>元</p>
            </li>
            <li>
                <p><i>6</i>元</p>
            </li>
            <li>
                <p><i>5</i>元</p>
            </li>
            <li>
                <p><i>4</i>元</p>
            </li>
            <li>
                <p><i>3</i>元</p>
            </li>
            <li>
                <p><i>2</i>元</p>
            </li>
            <li>
                <p><i>1</i>元</p>
            </li>
        </ul>
    </div>
    <input type="button" class="pwd-btn change_product" value="确 认" id="buybtn">
    </form>
</div>
<div class="mask none"></div>
<script type="text/javascript">
$(function(){
//    $("#selBottom").select({
////        "position":"bottom"
//    });
//    $("#selBottom").on('change', function(){
//        var val = $("#selBottom").val();
//        counts = parseInt(val);
//        setTimeout(function(){
//            TZCOUNTS.text = '选择投注金额:' + counts + '元';
//        },10);
//
//    })
    $("#buybtn,.back").on('touchend', function(){
        setTimeout(pop_Close,10);
//        pop_Close();
    })
    $('.active ul li').on('touchend',function () {
        $(this).addClass('slct').siblings().removeClass('slct');
        var text = $(this).find('i').text();
        $('.active h1 b').text(text);
        counts = parseInt(text);
        setTimeout(function(){
            TZCOUNTS.text = '选择金额:' + counts + '元';
        },10);
    });

})
function pop_Open() {
    $('#buildBox').show();
    $(".mask").show();
}


function pop_Close() {
    $('#buildBox').hide();
    $(".mask").hide();
    var text = $(".active ul li.slct").find('i').text();
    counts = parseInt(text);
    setTimeout(function(){
        TZCOUNTS.text = '选择金额:' + counts + '元';
    },10);
}
LInit(35, "mylegend", 320, 522, main);
LGlobal.stageScale = LStageScaleMode.EXACT_FIT;
LSystem.screen(LStage.FULL_SCREEN);

var loadingLayer,
        imglist = {},
        imgData = [],
        box,
        resultLayer,
        decs = [],
        TZLAYER1,
        TZLAYER2,
        COUNTS,
        TZCOUNTS,
        shareIcon,
        isSelect = false,
        con = 0,
        counts = 0,
        W,
        TZ,
        isOpen = true,
        ROOT = '',
        title = '',
        dice_cnt = 0;
        isAllScreen = false;
function main() {

    imgData.push({name: "d_box", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d_box.png"});
    imgData.push({name: "bgs5", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/bgs5.jpg"});
    imgData.push({name: "d1", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d1.png"});
    imgData.push({name: "d2", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d2.png"});
    imgData.push({name: "d3", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d3.png"});
    imgData.push({name: "d4", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d4.png"});
    imgData.push({name: "d5", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d5.png"});
    imgData.push({name: "d6", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/d6.png"});
    imgData.push({name: "open_on", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/open_on.png"});
    imgData.push({name: "open_out", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/open_out.png"});
    imgData.push({name: "lose", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/loseBg.png"});
    imgData.push({name: "winBG", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/winBg.png"});
    imgData.push({name: "shareBg", path: "/Public/Wap/jinrong/Mobile/Public/js/dice/img/sharebg.png"});
    loadingLayer = new LoadingSample1();

    addChild(loadingLayer);
    LLoadManage.load(
            imgData,
            function (progress) {
                loadingLayer.setProgress(progress);
            },
            function (result) {
                imglist = result;
                removeChild(loadingLayer);
                loadingLayer = null;
                gameInit();
            }
    );
}

function gameInit() {
    bgLayer = new LSprite(),
    bgImageData = new LBitmapData(imglist['bgs5']),
    bgImg = new LBitmap(bgImageData);

    var scale = 320 / bgImg.getWidth();
    bgImg.scaleX = scale;
    bgImg.scaleY = scale;
    bgLayer.addChild(bgImg);
    this.addChild(bgLayer);

    decs[0] = new LSprite();
    decs[1] = new LSprite();
    decs[2] = new LSprite();
    decs[0].x = 90;
    decs[0].y = 100;
    decs[1].x = 160;
    decs[1].y = 60;
    decs[2].x = 160;
    decs[2].y = 140;

    this.addChild(decs[0]);
    this.addChild(decs[1]);
    this.addChild(decs[2]);

    box = new LSprite();
    var boxImageData = new LBitmapData(imglist['d_box']),
            boxImage = new LBitmap(boxImageData);

    box.addChild(boxImage);
    box.x = 70;

    this.addChild(box);

    var sureBtnDataOn = new LBitmapData(imglist['open_on']),
            sureBtnDataOut = new LBitmapData(imglist['open_out']),
            sureImgOn = new LBitmap(sureBtnDataOn),
            sureImgOut = new LBitmap(sureBtnDataOut),
            sureBTN = new LButton(sureImgOut, sureImgOn, sureImgOut);

    sureBTN.x = 118;
    sureBTN.y = 398;
    this.addChild(sureBTN);
    sureBTN.addEventListener(LMouseEvent.MOUSE_UP, onHandler);

    TZLAYER1 = new LSprite();
    TZLAYER1.graphics.drawRect(0, "", [0, 5, 145, 100], true, "");
    TZLAYER1.alpha = 0;
    TZLAYER1.x = 10;
    TZLAYER1.y = 280;

    TZLAYER2 = new LSprite();
    TZLAYER2.graphics.drawRect(0, "", [0, 5, 145, 100], true, "");
    TZLAYER2.alpha = 0;
    TZLAYER2.x = 160;
    TZLAYER2.y = 280;


    this.addChild(TZLAYER1);
    this.addChild(TZLAYER2);
    TZLAYER1.addEventListener(LMouseEvent.MOUSE_UP, onSelectHandler);
    TZLAYER2.addEventListener(LMouseEvent.MOUSE_UP, onSelectHandler2);


    COUNTS = new LTextField();
    COUNTS.text = '余额:' + "{$user['money']}" + '元';
    COUNTS.color = "#ff0000";
    COUNTS.weight = "bold";
    COUNTS.x = 0;
    COUNTS.size = 10;
    COUNTS.y = 500;
    COUNTS.alpha = 0;

    this.addChild(COUNTS);

    upState2 = new LPanel("#f9f300",100,25);
    TZCOUNTS = new LTextField();
    TZCOUNTS.text = '选择金额:'+ counts +'元';
    TZCOUNTS.color = "#000000";
    TZCOUNTS.size = 10;
    TZCOUNTS.font = "Microsoft YaHei";
    upState2.x = 5;
    upState2.y = 450;
    TZCOUNTS.x = (upState2.getWidth() - TZCOUNTS.getWidth())*0.5;
    TZCOUNTS.y = (upState2.getHeight() - TZCOUNTS.getHeight())*0.5 - 2;
    upState2.addChild(TZCOUNTS);
    this.addChild(upState2);
    upState2.addEventListener(LMouseEvent.MOUSE_UP, onSelectHandler3);

    var moreGameSpri = new LPanel("#f9f300",80,25);
    moreGameSpri.x = 230;
    moreGameSpri.y = 450;
    MOREGAME = new LTextField();
//    MOREGAME.weight = "bold";
    MOREGAME.font = "Microsoft YaHei";
    MOREGAME.size = 10;
    MOREGAME.color = "#000000";
    MOREGAME.text = '剩余次数:' + "{$user['dice_cnt']}";
    MOREGAME.x = (moreGameSpri.getWidth() - MOREGAME.getWidth())*0.5;
    MOREGAME.y = (moreGameSpri.getHeight() - MOREGAME.getHeight())*0.5 - 2;
    dice_cnt = parseInt("{$user['dice_cnt']}");
    moreGameSpri.addChild(MOREGAME);
    this.addChild(moreGameSpri);
//        moreGameSpri.addEventListener(LMouseEvent.MOUSE_UP, moreGameHandler);
}

function moreGameHandler() {
//    yw.moreGame();
}

function onSelectHandler() {
    if (isOpen) {
        isSelect = true;
    } else {
        return false;
    }
    TZ = 0;

    TZLAYER2.removeAllChild();
    TZLAYER1.removeAllChild();

    TZCOUNTS.text = '选择金额:' + counts + '元';
    COUNTS.text = '余额:' + "{$user['money']}" + '元';

    var TZ1 = new LShape();
    TZ1.graphics.add(function () {
        var ctx = LGlobal.canvas;
        ctx.beginPath();
        ctx.fillStyle = '#0e34f8';
        ctx.moveTo(0, 0);
        ctx.quadraticCurveTo(100, 18, 142, 12, 30);
        ctx.lineTo(146, 106);
        ctx.lineTo(0, 95);
        ctx.lineTo(0, 0);
        ctx.fill();
        ctx.closePath();
    });
    TZ1.alpha = 0.2;
    TZLAYER1.addChild(TZ1);
//    onSelectHandler3();
}
function onSelectHandler2() {
    if (isOpen) {
        isSelect = true;
    } else {
        return false;
    }
    TZ = 1;

    TZLAYER1.removeAllChild();
    TZLAYER2.removeAllChild();

    TZCOUNTS.text = '选择金额:' + counts + '元';
    COUNTS.text = '余额:' + "{$user['money']}" + '元';

    var TZ2 = new LShape();
    TZ2.graphics.add(function () {
        var ctx = LGlobal.canvas;
        ctx.beginPath();
        ctx.fillStyle = '#0e34f8';
        ctx.moveTo(5, 10);
        ctx.quadraticCurveTo(100, 12, 150, 0, 20);
        ctx.lineTo(148, 100);
        ctx.lineTo(5, 108);
        ctx.lineTo(5, 10);
        ctx.fill();
        ctx.closePath();
    });
    TZ2.alpha = 0.2;
    TZLAYER2.addChild(TZ2);
//    onSelectHandler3();
}

function onSelectHandler3(){
//    $("#selBottom").trigger("touchend");
    pop_Open();
}

function onHandler() {
    if (!isSelect) {
        return false;
    }
    if(counts <= 0){
        showLoading("请点击选择金额，设置投注金额",2000);
        return false;
    }
    isOpen = false;
    isSelect = false;
    if(dice_cnt <= 0){
        deal_ajax();
        return false;
    }

    LTweenLite.to(box, 0.4, {
        y: 0,
        x: 70,
        rotate: 0,
        loop: false,
        ease: LEasing.Sine.easeInOut
    })
    .to(box, 0.1, {x: -50, loop: false, ease: LEasing.Sine.easeInOut})
    .to(box, 0.1, {x: 150, loop: false, ease: LEasing.Sine.easeInOut})
    .to(box, 0.1, {
        x: 70, loop: false, ease: LEasing.Sine.easeInOut, onComplete: function () {
            isOpen = false;
        }
    });
    LTweenLite.to(box, 0.4, {
        y: 0,
        x: 70,
        rotate: 0,
        loop: false,
        ease: LEasing.Sine.easeInOut
    })
            .to(box, 0.1, {x: -50, loop: false, ease: LEasing.Sine.easeInOut})
            .to(box, 0.1, {x: 150, loop: false, ease: LEasing.Sine.easeInOut})
            .to(box, 0.1, {
                x: 70, loop: false, ease: LEasing.Sine.easeInOut, onComplete: function () {
                    isOpen = false;
                }
            });
    setTimeout(deal_ajax, 1600);
}



function gameResult(d) {
    var code = d.points.split('-');
    console.log(d);


    decs[0].removeAllChild();
    decs[1].removeAllChild();
    decs[2].removeAllChild();


    decs[0].addChild(new LBitmap(new LBitmapData(imglist['d' + code[0]])));
    decs[1].addChild(new LBitmap(new LBitmapData(imglist['d' + code[1]])));
    decs[2].addChild(new LBitmap(new LBitmapData(imglist['d' + code[2]])));

    decs[0].visible = true;
    decs[1].visible = true;
    decs[2].visible = true;
    LTweenLite.to(box, 1, {
        y: -190,
        x: 300,
        loop: false,
        rotate: 45,
        ease: LEasing.Sine.easeInOut,
        onComplete: gameResultShow(d)
    });
}

function gameResultShow(d) {
    var t = setTimeout(function () {
        clearTimeout(t);
        if (resultLayer) {
            removeChild(resultLayer);
        }
        resultLayer = new LSprite();
        W = new LShape();
        if (d.result == 0) {
            W.graphics.add(function () {
                var ctx = LGlobal.canvas;
                ctx.beginPath();
                ctx.fillStyle = '#e7ff9f';
                ctx.moveTo(-2, 0);
                ctx.quadraticCurveTo(100, 12, 145, 12, 22);
                ctx.lineTo(145, 106);
                ctx.quadraticCurveTo(100, 106, -2, 98, 10);
                ctx.lineTo(-2, 10);
                ctx.fill();
                ctx.closePath();
            });
            TZLAYER1.addChild(W);
        } else {
            W.graphics.add(function () {
                var ctx = LGlobal.canvas;
                ctx.beginPath();
                ctx.fillStyle = '#e7ff9f';
                ctx.moveTo(4, 12);
                ctx.quadraticCurveTo(100, 12, 150, 0, 20);
                ctx.lineTo(150, 96);
                ctx.quadraticCurveTo(100, 106, 4, 106, 10);
                ctx.lineTo(4, 10);
                ctx.fill();
                ctx.closePath();
            });
            TZLAYER2.addChild(W);
        }

        if (d.result === TZ) {

            gameWin(d);

        } else {

            gameLose(d);

        }

        W.alpha = 0.8;

        LTweenLite.to(W, 0.4, {alpha: 0.5, loop: true, ease: LEasing.Sine.easeInOut}).to(W, 0.5, {
            alpha: 0.8,
            loop: true,
            ease: LEasing.Sine.easeInOut
        });
    }, 1500);

    setTimeout(function(){
        TZCOUNTS.text = '选择金额:' + counts + '元';
        COUNTS.text = '余额:' + d.money + '元';
        MOREGAME.text = '剩余次数:' + d.dice_cnt;
        dice_cnt = d.dice_cnt;

    }, 2500);
}

function gameRestart(e) {
//    resultLayer.removeAllChild();
    TZLAYER1.removeAllChild();
    TZLAYER2.removeAllChild();

    LTweenLite.to(box, 0.4, {
        y: 0,
        x: 70,
        rotate: 0,
        loop: false,
        ease: LEasing.Sine.easeInOut,
        onComplete: decsHide
    })
            .to(box, 0.1, {x: -100, loop: false, ease: LEasing.Sine.easeInOut})
            .to(box, 0.1, {x: 200, loop: false, ease: LEasing.Sine.easeInOut})
            .to(box, 0.1, {
                x: 70, loop: false, ease: LEasing.Sine.easeInOut, onComplete: function () {
                    isOpen = true;
                }
            });
}

function decsHide() {
    decs[0].visible = false;
    decs[1].visible = false;
    decs[2].visible = false;
}

function gameWin(d) {
    var html = '<h3>您赢了</h3>';
    html += '<p>本次您赢了' + counts + '元</p>';
    html += '<p>您的余额为<span style="color:red">' + d.money + '</span>元, 今天还可以玩<span style="color:red">'+ d.dice_cnt +'</span>局</p>';
    html += '<button  class="pwd-btn" ontouchend="hideLoading();gameRestart();">再来一盘</button>';
    showLoading(html);
    return;
//    var resImg = new LBitmap(new LBitmapData(imglist['winBG'])),
//            restartBtn = new LSprite(),
//            shareBtn = new LSprite(),
//            conTEXT = new LTextField();
//
//    resultLayer.addChild(resImg);
//    resultLayer.x = 25;
//    resultLayer.y = 0;
//
//    conTEXT.text = '已经连赢' + con + '把，累计奖金' + counts + '强币';
//    conTEXT.color = '#FFFFFF';
//    conTEXT.size = 10;
//    conTEXT.weight = 'bolder';
//    conTEXT.y = 188;
//    conTEXT.x = 40;
//
//
//
//    restartBtn.graphics.drawRect(0, "", [40, 210, 90, 35], true, "");
//    restartBtn.alpha = 0;
//    shareBtn.graphics.drawRect(0, "", [141, 210, 90, 35], true, "");
//    shareBtn.alpha = 0;
//    //shareBtn.x=50;
//
//    resultLayer.addChild(conTEXT);
//    resultLayer.addChild(restartBtn);
//    resultLayer.addChild(shareBtn);
//
//    addChild(resultLayer);
//    restartBtn.addEventListener(LMouseEvent.MOUSE_UP, gameRestart);
//    shareBtn.addEventListener(LMouseEvent.MOUSE_UP, shareHandler);
}

function gameLose(d) {
    var html = '<h3>您输了</h3>';
    html += '<p>本次您输了' + counts + '元</p>';
    html += '<p>您的余额为<span style="color:red">' + d.money + '</span>元, 今天还可以玩<span style="color:red">'+ d.dice_cnt +'</span>局</p>';
    html += '<button class="pwd-btn" ontouchend="hideLoading();gameRestart();">再来一盘</button>';
    showLoading(html);
    return;
//    var resImg = new LBitmap(new LBitmapData(imglist['lose']));
//    resultLayer.addChild(resImg);
//    resultLayer.x = 25;
//    resultLayer.y = 100;
//
//    var restartBtn = new LSprite(),
//            shareBtn = new LSprite();
//
//    restartBtn.graphics.drawRect(0, "", [40, 95, 90, 35], true, "");
//    restartBtn.alpha = 1;
//    shareBtn.graphics.drawRect(0, "", [141, 95, 90, 35], true, "");
//    shareBtn.alpha = 1;
//    //shareBtn.x=50;
//
//    resultLayer.addChild(restartBtn);
//    resultLayer.addChild(shareBtn);
//
//    addChild(resultLayer);
//    restartBtn.addEventListener(LMouseEvent.MOUSE_UP, gameRestart);
//    shareBtn.addEventListener(LMouseEvent.MOUSE_UP, shareHandler);
}

//下单发送ajax
function deal_ajax() {

    var deal_amount; //下单金额
    var captial; //资产种类
    var captial_id;
    var product; //资产
    var finish_time; //到期时间
    var dircetion; //方向
    var deal_value; //下单点位
    var yield; //收益率
    var expect_profit; //收益值
    var faild_profit; //保底值
    var msg;
    //获取收益率
    yield = 0;

    faild_profit = 0;

    var deal_amount = counts;
    if (deal_amount == '') {
        deal_amount = 10;
    }
    if (!deal_amount) {
        deal_amount = 10;
    } else if (deal_amount < 1) { //最低下单金额限制
        showLoading('下单金额过低，无法交易！', 2000);

        return 0;
    }
    expect_profit = 0;
    captial = 'DICE';

    //deal_value = $("#nowpotis").text();
    deal_value = 0;


    finish_time = new Date().getTime()/1000;
    deal_time = parseInt(finish_time);

    jQuery.ajax({
        type: 'post',
        url: "/Wap/Trading/deal_dice",
        data: "amount=" + deal_amount + "&trade_time=" + deal_time + "&capital=" + captial + "&product=" + "DICE" + "&dircetion=" + TZ + "&sec=" + finish_time + "&deal_value=" + deal_value + "&yield=" + yield +"&expect_profit=" + expect_profit + "&faild_profit=" + faild_profit,
        dataType: 'JSON',
        async: true,
        //timeout: 900,
        error: function (data) {
            showLoading('下单失败！', 2000);
            gameRestart();
            return 0;
        },
        success: function (data_t) {
            var json_data = data_t;
            //var json_data = eval(data_t);
            if (json_data['type'] == 'success') {
                var d = json_data["data"];
                gameResult(d);


            } else if (json_data['type'] == 'error') {
                //alert(json_data['error']);
                showLoading(json_data['error'], 2000);
                gameRestart();

            }
            return 0;
        }
    });

}

function shareHandler() {

}
function updateShare(score){
    console.log(score);
}
$(function(){

    $('.jz-footer ul a').removeClass('active');

    $('.jz-footer ul li').eq(1).find('a').addClass('active');
    $('.jz-footer ul a').on('touchend', function(){
        var href = $(this).attr("href");
        window.location.href = href;
    })
})

</script>
<include file="Public:footer"/>
</body>
</html>